package fenzhixianjie.onClass.exer03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

class Read {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        Read read = new Read();
        int m = read.nextInt(), n = read.nextInt();
        int startRow = -1, startCol = -1;
        int initBlood = read.nextInt();
        char[][] mat = new char[m][n];
        for (int i = 0; i < m; i++) {
            String line = read.next();
            for (int j = 0; j < n; j++) {
                char value = line.charAt(j);
                mat[i][j] = value;
                if (value == '!') {
                    startRow = i;
                    startCol = j;
                }
            }
        }
        int[][] nextPos = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
        Queue<int[]> queue = new LinkedList<>();
        queue.offer(new int[] {startRow, startCol, initBlood});
        int step = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            while (size > 0) {
                int[] top = queue.poll();
                for (int i = 0; i < 4; i++) {
                    int nextRow = top[0] + nextPos[i][0];
                    int nextCol = top[1] + nextPos[i][1];
                    if (nextRow < 0 || nextRow >= m || nextCol < 0 || nextCol >= n) {
                        continue;
                    }
                    if (mat[nextRow][nextCol] == 'w') {
                        if (top[2] >= 2) {
                            queue.offer(new int[] {nextRow, nextCol, top[2] - 1});

                        }
                    } else if (mat[nextRow][nextCol] == '*') {
                        queue.offer(new int[] {nextRow, nextCol, top[2]});
                    } else if (mat[nextRow][nextCol] == '+') {
                        System.out.println(step + 1);
                        return;
                    }
                }
                size--;
            }
            step++;
        }
        System.out.println(-1);
    }
}
